/*	kd:
	Here comes a good one. This outputs, based on a passed aspect ratio, a
	screen edge-aligned coordinate system that fits a rectangle to fill out
	p percent of the screen width or height. Since gzd devs have made it a point
	to allow resolution independent rendering, we should follow suit.
	
	The coordinates output are normal. If you get the x- and y-values, they
	represent the right and bottom edges of the returned box respectively.
	
	If only there were screen resized events.
	
	Is not tight-loop code. */

class Gcs_ScreenCoords {
	/* float m_aspect;
	
	void CacheScreenData () {
		m_aspect = Screen.GetAspectRatio();
	} */
	
	static float, float ScaleDiffToWidth (float dx, float dy, float width) {
		float scale = Screen.GetWidth() / width;
		return dx * scale, dy * scale;
	}
	
	static float, float AspectCoord (float dx, float dy) {
		float aspect = Screen.GetAspectRatio();
		
		if(1 < aspect) {
			return dx, dy / aspect;
		}
		
		return dx * aspect, dy;
	}
	
	static float, float AdjustForAspect (float dx, float dy) {
		float aspect = Screen.GetAspectRatio();
		
		if(1 < aspect) {
			return dx / aspect, dy;
		}
		
		return dx, dy * aspect;
	}
	
	/*	This fits a rectangular proportionally inside of the screen bounds
		given by the aspect ratio. It will try to have either maximum width or
		height. This is similar to what HudMessage does in acs. */
	
	static
	float, float, float, float CenteredSquishBox (float width, float height) {
		height = max(0.001, height);
		float aspect = Screen.GetAspectRatio();
		float box_aspect = width / height;
		float x, y;
		
		/*	Container is wider than box passed; maximise height. */
		if(box_aspect < aspect) {
			width /= height * aspect;
			x = 0.5 * (1 - width);
			y = 0;
			height = 1;
		}
		
		/*	Container is higher than box passed; maximise width. */
		else {
			height /= width / aspect;
			x = 0;
			y = 0.5 * (1 - height);
			width = 1;
		}
		
		return x, y, width, height;
	}
}